<template>
  <div class="entryAdd">
    <el-dialog title="账号录入" :visible="dialogVisible" width="30%" :before-close="handleClose">
      <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px">
        <el-form-item prop="accountType" label="账户类型">
          <!--          <el-input v-model="ruleForm.tepy" size="mini" />-->
          <el-select v-model="ruleForm.accountType" @change="tepyChange" size="mini" placeholder="请选择账户类型">
            <el-option v-for="item in AccountType" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="challengeProject" label="挑战项目">
          <!--          <el-input v-model="ruleForm.project" size="mini" />-->
          <el-select v-model="ruleForm.challengeProject" @change="project" size="mini" placeholder="请选择挑战项目">
            <el-option v-for="item in challengesList" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="stage" label="所属阶段:">
          <!-- <el-input v-model="ruleForm.stage" size="mini" placeholder="归属邮箱" /> -->
          <el-select v-model="ruleForm.stage" @change="stageChange" size="mini" :disabled="disabledStage"
            placeholder="请选择所属阶段">
            <el-option v-for="item in PhaseList2" :key="item.id" :label="item.name" :value="item.id" />
          </el-select>
        </el-form-item>
        <el-form-item prop="accountMoney" label="账户规模:">
          <!--          <el-input v-model="ruleForm.FeeAmount" size="mini" placeholder="收费金额"/>-->
          <el-input v-model="ruleForm.accountMoney" placeholder="请选择账户规模" size="mini" />
        </el-form-item>
        <el-form-item prop="accountMoney" label="交易资金:">
          <el-input v-model.number="ruleForm.expansionPlanFunds" placeholder="请选择交易资金" size="mini" />
        </el-form-item>
        <el-form-item prop="expansionPlan" label="扩展计划">
          <!--          <el-input v-model="ruleForm.project" size="mini" />-->
          <el-select v-model="ruleForm.expansionPlan" :disabled="disabledExpansionPlan" size="mini" placeholder="请选择">
            <el-option v-for="item in Expansion" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="accountNumber" label="交易账号:">
          <el-input v-model="ruleForm.accountNumber" size="mini" placeholder="交易账号" />
        </el-form-item>
        <el-form-item prop="accountPassword" label="交易密码:">
          <el-input v-model="ruleForm.accountPassword" size="mini" placeholder="交易密码" />
        </el-form-item>
        <el-form-item prop="readonlyPassword" label="只读密码:">
          <el-input v-model="ruleForm.readonlyPassword" size="mini" placeholder="交易密码" />
        </el-form-item>
        <el-form-item prop="accountLever" label="交易杠杆:">
          <!-- <el-input size="mini" placeholder="账户杠杆" /> -->
          <el-select v-model="ruleForm.accountLever" size="mini" placeholder="账户杠杆">
            <el-option label="30" :value="30" />
            <el-option label="100" :value="100" />
            <el-option label="300" :value="300" />
            <el-option label="500" :value="500" />
          </el-select>
        </el-form-item>
        <el-form-item prop="emails" label="归属邮箱:">
          <el-input v-model="ruleForm.emails" size="mini" placeholder="归属邮箱" />
        </el-form-item>
        <el-form-item prop="platform" label="平台">
          <!--          <el-input v-model="ruleForm.guishupingtai" size="mini" placeholder="归属平台" />-->
          <el-select v-model="ruleForm.platform" size="mini" placeholder="请选择平台">
            <el-option v-for="item in BelongingPlatform" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="plateau" label="经纪商:">
          <el-select v-model="ruleForm.plateau" size="mini" placeholder="请选择">
            <el-option label="Valutrades" value="1">
            </el-option>
            <el-option label="Exness" value="2">
            </el-option>
            <el-option label="FXPRO" value="3">
            </el-option>
            <el-option label="PoolTrader" value="4">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="servers" label="交易服务器">
          <el-input v-model="ruleForm.servers" size="mini" placeholder="服务器" />
        </el-form-item>
        <el-form-item prop="fengkongServers" label="风控服务器">
          <el-input v-model="ruleForm.fengkongServers" size="mini" />
        </el-form-item>
        <el-form-item prop="fengkongZhuangtai" label="是否风控:">
          <el-select v-model="ruleForm.fengkongZhuangtai" size="mini" placeholder="请选择是否风控">
            <el-option label="否" :value="0" />
            <el-option label="是" :value="1" />
          </el-select>
        </el-form-item>
        <el-form-item prop="accountTagName" label="账号标签:">
          <!--          <el-select v-model="ruleForm.accountTagName" size="mini" placeholder="请选择账号标签">-->

          <!--            <el-option-->
          <!--                label="日内"-->
          <!--                value="1"-->
          <!--            />-->
          <!--            <el-option-->
          <!--                label="非日内"-->
          <!--                value="2"-->
          <!--            />-->
          <!--          </el-select>-->
          <el-input v-model="ruleForm.accountTagName" size="mini" placeholder="请选择账号标签"></el-input>
        </el-form-item>
        <el-form-item prop="accountSource" label="账户性质:">
          <el-select v-model="ruleForm.accountSource" size="mini" placeholder="请选择账户性质">

            <el-option label="付费" value="1" />
            <el-option label="免费" value="2" />
          </el-select>
        </el-form-item>
        <!-- <el-form-item prop="accountSource" label="账号来源:">
          <el-select v-model="ruleForm.accountSource" size="mini" placeholder="请选择账号来源">

            <el-option label="网页端" value="1" />
            <el-option label="软件端" value="2" />
          </el-select>
        </el-form-item> -->
        <!--        <el-form-item prop="accountCharges" label="账户费用:">-->
        <!--          <el-input v-model="ruleForm.accountCharges" size="mini" placeholder="账户费用"/>-->
        <!--        </el-form-item>-->
        <!--        <el-form-item v-if="radio === 1" prop="acctoll" label="收费标准:">-->
        <!--          <el-input v-model="ruleForm.acctoll" size="mini" placeholder="请输入收费标准"/>-->
        <!--        </el-form-item>-->
        <el-form-item>
          <el-row type="flex" justify="end" style="margin-top: 10px;">
            <el-button size="mini" @click="handleClose">取 消</el-button>
            <el-button size="mini" type="primary" @click="btnOK">确 定</el-button>
          </el-row>
        </el-form-item>
      </el-form>

    </el-dialog>
  </div>
</template>

<script>

import { PhaseList1, ExpansionPlan, BelongingPlatform, AccountType, challenges } from '@/utils'
import { addSave, getAccountType, getChallengeProject } from '@/api/Tradingacct'

export default {
  name: 'VueAdminEntryAdd',
  props: {
    dialogVisible: {
      default: false,
      type: Boolean
    },
    radio: {
      default: 0,
      type: Number
    }
  },
  data() {
    return {
      // 平台
      platform: [
        {
          id: 1,
          name: 'Mt4'
        },
        {
          id: 2,
          name: 'Mt5'
        },
        {
          id: 3,
          name: 'Ctrader'
        }
      ],
      ruleForm: {
        accountType: null, // 账户类型
        challengeProject: null, // 挑战项目
        // guishupingtai: '',
        servers: null, // 交易服务器
        accountNumber: null, // 交易账号
        accountPassword: null, // 交易密码
        accountMoney: null, // 交易资金
        // accountCharges: '', // 账户费用
        accountLever: 100, // 交易杠杆
        emails: null, // 归属邮箱
        // pattern: 0,
        plateau: null, //经纪商
        platform: null, //平台
        fengkongZhuangtai: 1, // 是否风控
        stage: null, // 所属阶段
        fengkongServers: null, // 风控服务器
        // acctoll: 0,
        expansionPlan: null, // 扩展计划
        readonlyPassword: null, // 只读密码
        accountTagName: null, // 账号标签
        accountSource: null, // 账号来源
        expansionPlanFunds: null, // 交易资金
      }, // 信息
      rules: {
        accountType: [
          { required: true, message: '账户类型不可以为空', trigger: ['blur', 'change'] }],
        challengeProject: [
          { required: true, message: '挑战项目不可以为空', trigger: ['blur', 'change'] }],
        // guishupingtai: [
        //   {required: true, message: '归属平台不可以为空', trigger: ['blur', 'change']}],
        servers: [
          { required: true, message: '交易服务器不可以为空', trigger: ['blur', 'change'] }],
        accountNumber: [
          { required: true, message: '交易账号不可以为空', trigger: ['blur', 'change'] }],
        accountPassword: [
          { required: true, message: '交易密码不可以为空', trigger: ['blur', 'change'] }],
        accountMoney: [
          { required: true, message: '交易资金不可以为空', trigger: ['blur', 'change'] }],
        accountCharges: [
          { required: true, message: '账户费用不可以为空', trigger: ['blur', 'change'] }],
        accountLever: [
          { required: true, message: '杠杆不可以为空', trigger: ['blur', 'change'] }],
        emails: [
          { required: true, message: '归属邮箱不可以为空', trigger: ['blur', 'change'] }],
        plateau: [
          { required: true, message: '经纪商不可以为空', trigger: ['blur', 'change'] }],
        platform: [
          { required: true, message: '平台不可以为空', trigger: ['blur', 'change'] }],
        fengkongZhuangtai: [
          { required: true, message: '风控状态不可以为空', trigger: ['blur', 'change'] }
        ],
        stage: [
          { required: true, message: '所属阶段不可以为空', trigger: ['blur', 'change'] }
        ],
        fengkongServers: [
          { required: true, message: '风控服务器不可以为空', trigger: ['blur', 'change'] }
        ],
        expansionPlan: [
          { required: true, message: '扩展计划不可以为空', trigger: ['blur', 'change'] }
        ],
        // FeeAmount: [
        //   {required: true, message: '收费金额不可以为空', trigger: ['blur', 'change']}
        // ],
        ReadOnlyPassword: [
          { required: true, message: '只读密码不可以为空', trigger: ['blur', 'change'] }
        ],
        accountTagName: [
          { required: true, message: '账号标签不可以为空', trigger: ['blur', 'change'] }
        ],
        accountSource: [
          { required: true, message: '账号来源不可以为空', trigger: ['blur', 'change'] }
        ]
      }, // 校验
      // 挑战项目
      projectArr: [],
      disabledStage: false, // 所属阶段输入框禁用
      disabledExpansionPlan: false, // 扩展计划input禁用
      accountMoney: [], // 账户费用
      Expansion: [], // 扩展计划
      challengesList: [], // 挑战项目
      PhaseList2: [], // 所属阶段
    }
  },
  computed: {
    // 所属阶段
    PhaseList1() {
      return PhaseList1
    },
    // 扩展计划
    ExpansionPlan() {
      return ExpansionPlan
    },
    // 归属平台
    BelongingPlatform() {
      return BelongingPlatform
    },
    // 账户类型
    AccountType() {
      return AccountType
    },
    // 挑战项目
    challenges() {
      return challenges
    }
  },
  watch: {
    radio: {
      // console.log(newVal,'newVal');
      // if(newVal){
      //   console.log(newVal);
      //   this.ruleForm.pattern = newVal
      // }else{
      //   this.ruleForm.pattern =
      // }
      handler(newVal, oldVal) {
        this.ruleForm.pattern = newVal
      },
      deep: true
    }
  },

  mounted() {
    // this.getuseACCouyt()
  },

  methods: {
    async getProject() {
      const { data } = await getChallengeProject()
      this.projectArr = data
    },
    // 取消
    handleClose() {
      this.$refs.ruleForm.resetFields()
      this.$emit('update:dialogVisible', false)
    },
    // 确定
    async btnOK() {
      this.stageParam()
      this.expansionPlanParam()
      // this.accountMoneyParam()
      this.challengeProjectParam()
      await this.$refs.ruleForm.validate()
      await addSave({ ...this.ruleForm, pattern: this.radio })
      this.$emit('refresh')
      this.handleClose()
    },
    async getuseACCouyt() {
      const { data } = await getAccountType()
      this.AccountType = data
    },

    /**
     * @author 焦延龙 <19131965027@163.com>
     * @description  修改所属阶段传入的参数
     * @date  2024/03/11
     */
    stageParam() {
      switch (this.ruleForm.stage) {
        case '验证':
          this.ruleForm.stage = 0
          break;
        case '确认':
          this.ruleForm.stage = 1
          break;
        case '合作':
          this.ruleForm.stage = 2
          break;
        case '比赛':
          this.ruleForm.stage = 3
          break;
      }
    },


    /**
     * @author 焦延龙 <19131965027@163.com>
     * @description 交易资金传入参数修改
     * @date 2024/03/11
     */

    accountMoneyParam() {
      switch (this.ruleForm.accountMoney) {
        case 5000:
          this.ruleForm.accountMoney = 0
          break;
        case 20000:
          this.ruleForm.accountMoney = 1
          break;
        case 60000:
          this.ruleForm.accountMoney = 2
          break;
        case 100000:
          this.ruleForm.accountMoney = 3
          break;
        case 14000:
          this.ruleForm.accountMoney = 4
          break;
        case 40000:
          this.ruleForm.accountMoney = 5
          break;
        case 90000:
          this.ruleForm.accountMoney = 6
          break;
        case 200000:
          this.ruleForm.accountMoney = 7
          break;
        case 80000:
          this.ruleForm.accountMoney = 8
          break;
        case 160000:
          this.ruleForm.accountMoney = 9
          break;
        case 260000:
          this.ruleForm.accountMoney = 10
          break;
        case 10000:
          this.ruleForm.accountMoney = 11
          break;
      }
    },

    /**
     * @author 焦延龙 <19131965027@163.com>
     * @description 扩展计划传入参数修改
     * @date 2024/03/11
     */
    expansionPlanParam() {
      switch (this.ruleForm.expansionPlan) {
        case 'L0':
          this.ruleForm.expansionPlan = 0
          break;
        case 'L1':
          this.ruleForm.expansionPlan = 1
          break;
        case 'L2':
          this.ruleForm.expansionPlan = 2
          break;
        case 'L3':
          this.ruleForm.expansionPlan = 3
          break;
        case 'L4':
          this.ruleForm.expansionPlan = 4
          break;
        case 'L5':
          this.ruleForm.expansionPlan = 5
          break;
        case 'L6':
          this.ruleForm.expansionPlan = 6
          break;
        case 'L7':
          this.ruleForm.expansionPlan = 7
          break;
        case 'L8':
          this.ruleForm.expansionPlan = 8
          break;
      }
    },
    /**
     * @author 焦延龙 <19131965027@163.com>
     * @description 挑战项目传入参数修改
     * @date
     */
    challengeProjectParam() {
      switch (this.ruleForm.challengeProject) {
        case '评估':
          this.ruleForm.challengeProject = 0
          break;
        case '即时':
          this.ruleForm.challengeProject = 1
          break;
        case '固定':
          this.ruleForm.challengeProject = 2
          break;
        case '比赛':
          this.ruleForm.challengeProject = 3
          break;
        case '股票':
          this.ruleForm.challengeProject = 4
          break;
      }
    },

    /**
     * @author 焦延龙 <19131965027@163.com>
     * @description 挑战项目输入框联动
     * @param val 输入框的值
     * @date
     */
    project(val) {
      switch (val) {
        case '0':
          this.accountMoney = []
          this.accountMoney = [...this.accountMoney, 5000, 20000, 60000, 100000]
          this.ruleForm.accountMoney = 5000
          this.ruleForm.stage = '验证'
          this.PhaseList2 = this.PhaseList1
          this.disabledStage = false
          this.stageChange()
          this.AssessmentChallengeStage()
          break;
        case '1':
          this.accountMoney = []
          this.accountMoney = [...this.accountMoney, 14000, 40000, 60000, 90000]
          this.ruleForm.accountMoney = 14000
          this.ruleForm.stage = '合作'
          this.PhaseList2 = this.PhaseList1
          this.disabledStage = true
          this.disabledExpansionPlan = false
          this.ruleForm.expansionPlan = 'L1'
          this.AssessmentChallengeStage()
          break;
        case '2':
          this.accountMoney = []
          this.accountMoney = [...this.accountMoney, 100000, 200000]
          this.ruleForm.accountMoney = 100000
          this.ruleForm.stage = '合作'
          this.PhaseList2 = this.PhaseList1
          this.disabledStage = true
          this.disabledExpansionPlan = false
          this.ruleForm.expansionPlan = 'L1'
          this.AssessmentChallengeStage()
          break;
        case '3':
          this.accountMoney = []
          this.accountMoney = [...this.accountMoney, 10000]
          this.ruleForm.accountMoney = 10000
          this.ruleForm.stage = '比赛'
          this.PhaseList2 = this.PhaseList1
          this.disabledStage = true
          // this.stageChange()
          this.AssessmentChallengeStage()
          break;
        case '4':
          this.accountMoney = []
          this.accountMoney = [...this.accountMoney, 20000, 80000, 160000, 260000]
          this.ruleForm.accountMoney = 20000
          this.ruleForm.stage = '验证'
          this.PhaseList2 = [...this.PhaseList1.slice(0, 1), ...this.PhaseList1.slice(2, 3)]
          this.disabledStage = false
          this.stageChange()
          this.AssessmentChallengeStage()
          break;
      }
    }
    ,
    AssessmentChallengeStage() {
      switch (this.ruleForm.challengeProject) {
        case '评估' || '0':
          switch (this.ruleForm.accountMoney) {
            case 5000:
              this.Expansion = this.ExpansionPlan.slice(0, 5)
              break;
            case 20000:
              this.Expansion = this.ExpansionPlan.slice(0, 4)
              break;
            case 60000:
              this.Expansion = this.ExpansionPlan.slice(0, 3)
              break;
            case 100000:
              this.Expansion = this.ExpansionPlan.slice(0, 8)
              break;
          }
          break;
        case '即时' || '1':
          this.Expansion = this.ExpansionPlan.slice(0, 8)
          break;
        case '固定' || '2':
          this.Expansion = this.ExpansionPlan.slice(0, 4)
          break;
        case '比赛' || '3':
          this.disabledExpansionPlan = true
          this.ruleForm.expansionPlan = 'L0'
          break;
        case '股票' || '4':
          this.Expansion = this.ExpansionPlan.slice(0, 5)
          break;
      }

    }
    ,
    /**
     * @author 焦延龙 <19131965027@163.com>
     * @description 改变当前input框状态
     * @param val 当前input的值
     * @date
     */
    stageChange(val) {
      console.log("22222", val)
      if (val !== 2) {
        this.disabledExpansionPlan = true
        this.ruleForm.expansionPlan = 'L0'
      } else {
        this.disabledExpansionPlan = false
        this.ruleForm.expansionPlan = 'L1'
      }
    }
    ,
    /**
     * @author 焦延龙 <19131965027@163.com>
     * @description 账户类型input
     * @param val 当前input的值
     * @date
     */
    tepyChange(val) {
      switch (val) {
        case '0':
          this.challengesList = this.challenges.slice(0, 4)
          const abc = this.challenges.slice(5)
          this.challengesList = this.challenges.slice(0, 4).concat(abc)
          this.ruleForm.challengeProject = '评估'
          this.project('0')
          break;
        case '1':
          this.challengesList = this.challenges.slice(4, 5)
          this.ruleForm.challengeProject = '股票'
          this.project('4')
          break;
      }
    }
  }
}
</script>

<style lang="scss" scoped>
::v-deep .el-input__inner {
  width: 170px !important;
}
</style>
